<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateElOrderTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('el_order', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->string('order_no'); //订单编号

            $table->integer('count')->unsigned()->default(0); //商品总数

            $table->integer('status')->unsigned()->default(0);  //订单状态：1生成订单,2支付订单,3取消订单,4作废订单,5完成订单,6退款
            $table->string('pay_type')->nullable();    //支付方式 包含支付宝，微信，余额支付
            $table->integer('pay_status')->unsigned()->default(0);  //支付状态：0未支付,1已支付
            $table->integer('distribution_status')->unsigned()->default(0); //发货状态：0未发货，1已发货
            $table->integer('distribution')->unsigned()->nullable(); //配送方式ID

            $table->string('coupon_item')->nullable(); //使用的优惠券编号

            $table->integer('items_total');  //商品总金额
            $table->integer('adjustments_total')->default(0);   //优惠金额，负数，包含了促销和优惠券以及其他优惠的总金额,默认为零因为可能没有优惠活动
            //$table->decimal('payable_amount', 8, 2)->default(0.00);   //应付商品金额
            /*$table->decimal('promotions_amount', 8, 2)->default(0.00);   //促销优惠金额*/
            /*$table->decimal('discount_amount', 8, 2)->default(1.00);   //折扣或涨跌价金额*/
            
            //$table->decimal('real_amount', 8, 2)->default(0.00);   //实付商品金额 = 应付商品金额-折扣-促销优惠

            /*$table->decimal('payable_freight', 8, 2)->default(0.00);   //应付运费金额
            $table->decimal('real_freight', 8, 2)->default(0.00);   //实付运费金额*/
            $table->integer('payable_freight')->default(0);   //应付运费金额
            $table->integer('real_freight')->default(0);      //实付运费金额

            //$table->decimal('order_amount', 8, 2)->default(0.00);   //订单总金额 = 商品实付金额+运费
            $table->integer('total');  //订单总金额:  items_total+adjustments_total+real_freight

            $table->string('accept_name')->nullable();  //收货人姓名
            $table->string('mobile')->nullable(); //电话号码
            //$table->integer('province')->unsigned()->nullable();    //收货省ID
            //$table->integer('city')->unsigned()->nullable();    //收货市ID
            //$table->integer('area')->unsigned()->nullable();    //区ID
            $table->string('address')->nullable();
            $table->string('address_name')->nullable();     //备用:收货地//详细地址址省市区名称
            
            $table->timestamp('pay_time')->nullable();  //付款时间
            $table->timestamp('send_time')->nullable();  //发货时间
            $table->timestamp('completion_time')->nullable();  //订单完成时间
            $table->timestamp('accept_time')->nullable();  //客户收货时间

            $table->integer('point')->unsigned()->nullable();   //增加的积分
            $table->string('message')->nullable();  //用户留言
            $table->integer('type')->default(0); //是否线上订单 0线上订单 1线下订单
            $table->string('note')->nullable();     //管理员备注

            $table->timestamps();
            $table->softDeletes();

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('el_order');
    }
}
